
from google.appengine.ext import db
from util.constants import DEV_TYPE_NAME_ANDROID as ANDROID
from util.constants import DEV_TYPE_NAME_CHROME as CHROME
from util.constants import DEV_TYPE_NAME_BB as BB


from util.constants import DATA_TYPE_IMAGE as IMAGE
from util.constants import DATA_TYPE_URL as URL
from util.constants import DATA_TYPE_PHONE_NO as PHONE_NO
from util.constants import DATA_TYPE_PLAIN_TXT as PLAIN_TXT

class DeviceOwner(db.Model):
	"""
	Data model class for owners of devices. Only created when a user undergoes
the optional registration"""
	account = db.UserProperty(required=True)
	date_created = db.DateTimeProperty(required=True, auto_now_add=True)

# Modelled with Expando because Android devices will contain
# another property 'version'
class Device(db.Expando):
	"""Data model class for devices registered with the server
	"""
	 # Pretty limiting way to model it but, hey
	device_type = db.StringProperty(required=True, \
		choices=set([ANDROID, CHROME, BB]))
	# If the device supports push notifications
	supports_push = db.BooleanProperty(required=True)
	# Date the device checked into the system last.
	date_signed_in = db.DateTimeProperty(required=True, auto_now_add=True)
	# Date of last activity by device
	date_last_activity = db.DateTimeProperty(required=False, auto_now_add=True)
	# A friendly name of the device. Added by user during registration.
	device_friendly_name = \
		db.StringProperty(verbose_name='Device\'s Friendly name', required=False)
	# A reference to the owner of the device
	owner = db.ReferenceProperty(DeviceOwner, \
		verbose_name='Device Owner', default=None, collection_name='devices')

# Modeled with Expando because all instances of this class will later
# contain another property 'data' which may be db.StringProperty, a
# db.BlobProperty, a db.LinkProperty or a db.PhoneNumberProperty
class ExchangedData(db.Expando):
	"""Data model class for data that is exchanged between clients.
	"""
	# Date data was added
	date_added = db.DateTimeProperty(required=True, auto_now_add=True)
	data_type = db.StringProperty(required=True, \
		choices=set([IMAGE, URL, PHONE_NO, PLAIN_TXT]))
	data_owner = db.ReferenceProperty(Device, required=True, \
		verbose_name='Data Owner', collection_name='all_owned_data')
	data_sender = db.ReferenceProperty(Device, required=True, \
		verbose_name='Data Sender', collection_name='all_sent_data')
